import { NodeSize } from '../config'

export default function sqlFileOutput(flow) {
  flow.register('SqlFileOutput', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M134.92419 294.521905l155.745524-0.024381V140.239238h-46.34819v75.166476L116.97981 88.039619 84.21181 120.783238l127.366095 127.414857H134.92419z'
            }
          ),
          h(
            'path',
            {
              fill: '#DBF3DB',
              d: 'M519.68 556.617143c21.308952 0 30.622476-9.069714 30.622476-24.941714v-58.416762c0-15.847619-9.313524-24.941714-30.622476-24.941715-21.284571 0-30.622476 9.094095-30.622476 24.941715v58.416762c0 15.872 9.337905 24.941714 30.622476 24.941714z'
            }
          ),
          h(
            'path',
            {
              fill: '#DBF3DB',
              d: 'M732.306286 816.761905l-1.414096-491.349334h-103.789714V221.598476h-172.690286l-153.478095 153.478095V816.761905h431.372191z m-137.337905-384.707048h22.942476v118.784h58.294857v21.113905h-81.237333v-139.897905z m-127.853714 40.789333c0-24.502857 15.481905-44.373333 52.565333-44.373333 37.10781 0 52.589714 19.870476 52.589714 44.373333v59.270096c0 20.187429-10.654476 37.61981-35.742476 42.666666l11.580952 26.160762-19.772952 8.972191-14.433524-34.206476c-33.572571-1.731048-46.811429-20.23619-46.811428-43.593143v-59.270096z m-43.715048 51.638858a8.508952 8.508952 0 0 0-2.291809-5.071238c-2.80381-2.755048-8.752762-4.583619-22.893715-7.801905-33.645714-7.533714-38.521905-14.799238-38.521905-44.080762 0-25.283048 11.337143-37.497905 45.763048-37.497905 11.897905 0 26.063238 1.633524 37.034667 4.534857l2.31619 0.609524-1.950476 20.260571-3.096381-0.682666a160.52419 160.52419 0 0 0-33.865143-3.779048c-21.016381 0-23.235048 3.705905-23.235047 17.164191 0 4.486095 0 7.850667 0.414476 10.556952 0.365714 2.438095 1.024 3.82781 2.121143 4.949333 2.633143 2.633143 8.265143 4.36419 21.991619 7.801905 36.717714 9.118476 39.619048 15.311238 39.619047 43.056762 0 24.966095-8.143238 39.497143-46.567619 39.497143-13.165714 0-29.062095-2.462476-40.96-7.265524l-2.194285-0.853333 3.900952-19.456 2.974476 0.902095a124.708571 124.708571 0 0 0 36.668953 5.729524c20.406857 0 23.210667-4.729905 23.210666-18.16381 0-4.36419 0-7.728762-0.438857-10.410666z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M772.33981 325.680762l-41.691429-41.691429h-62.098286V221.891048L626.834286 180.175238h-130.998857l-41.447619 41.423238h172.714666v103.814095h103.789714l1.414096 491.349334H300.909714V375.100952l-41.447619 41.447619V858.209524h514.413715z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M400.603429 553.057524c-11.995429 0-24.624762-1.974857-36.668953-5.729524l-2.974476-0.902095-3.900952 19.456 2.194285 0.853333c11.873524 4.803048 27.794286 7.265524 40.96 7.265524 38.424381 0 46.567619-14.531048 46.567619-39.497143 0-27.745524-2.901333-33.938286-39.619047-43.056762-13.726476-3.462095-19.358476-5.168762-21.991619-7.801905-1.097143-1.121524-1.755429-2.535619-2.121143-4.949333-0.414476-2.681905-0.414476-6.070857-0.414476-10.556952 0-13.458286 2.218667-17.16419 23.235047-17.164191 10.873905 0 23.356952 1.414095 33.865143 3.779048l3.096381 0.682666 1.950476-20.260571-2.31619-0.609524a156.550095 156.550095 0 0 0-37.034667-4.534857c-34.425905 0-45.763048 12.214857-45.763047 37.497905 0 29.257143 4.87619 36.547048 38.521904 44.080762 14.140952 3.218286 20.089905 5.046857 22.893715 7.801905a8.508952 8.508952 0 0 1 2.291809 5.071238c0.438857 2.681905 0.438857 6.046476 0.438857 10.410666 0.024381 13.433905-2.80381 18.16381-23.210666 18.16381zM676.205714 550.838857h-58.294857v-118.784h-22.942476v139.897905h81.237333z'
            }
          ),
          h(
            'path',
            {
              fill: '#DBF3DB',
              d: 'M513.926095 575.707429l14.433524 34.206476 19.772952-8.972191-11.580952-26.160762c25.088-5.046857 35.742476-22.479238 35.742476-42.666666v-59.270096c0-24.502857-15.481905-44.373333-52.589714-44.373333-37.083429 0-52.565333 19.870476-52.565333 44.373333v59.270096c-0.024381 23.356952 13.214476 41.837714 46.787047 43.593143z m-24.868571-102.448762c0-15.847619 9.337905-24.941714 30.622476-24.941715 21.308952 0 30.622476 9.094095 30.622476 24.941715v58.416762c0 15.872-9.313524 24.941714-30.622476 24.941714-21.284571 0-30.622476-9.069714-30.622476-24.941714v-58.416762z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M513.926095 575.707429l14.433524 34.206476 19.772952-8.972191-11.580952-26.160762c25.088-5.046857 35.742476-22.479238 35.742476-42.666666v-59.270096c0-24.502857-15.481905-44.373333-52.589714-44.373333-37.083429 0-52.565333 19.870476-52.565333 44.373333v59.270096c-0.024381 23.356952 13.214476 41.837714 46.787047 43.593143z m-24.868571-102.448762c0-15.847619 9.337905-24.941714 30.622476-24.941715 21.308952 0 30.622476 9.094095 30.622476 24.941715v58.416762c0 15.872-9.313524 24.941714-30.622476 24.941714-21.284571 0-30.622476-9.069714-30.622476-24.941714v-58.416762z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          'SQL文件输出'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
